<template>
  <div class="recommend">
    <div class="recommend-title">
      <h5>精品推荐</h5>
    </div>
    <div class="recommend-main">
      <div class="item"
        v-for="item in items" :key="item.id"
        @click="clickItem(item.id)"
        >
        <img v-lazy="item.pic" alt="">
        <div class="title">
          {{item.name}}
        </div>
        <div class="item-action">
          <div class="price">
            {{ item.minPrice | currency('￥') }}
          </div>
          <van-icon size="20" @click.stop="addCart(item)" class-prefix="icon" name="jia"/>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { currency } from '@/filters'
export default {
  props: {
    items: {
      type: Array,
      required: true
    }
  },
  methods: {
    clickItem (id) {
      this.$emit('clickItem', id)
    },
    addCart (item) {
      // 点击添加购物车按钮
      this.$emit('addCart', item)
    }
  },
  filters: {
    currency
  }
}
</script>

<style lang="scss" scoped>
.recommend{
  &-title{
    height: 40px;
    padding: 0 10px;
    color: #333;
    font-size: 18px;
    background-color: #f1f1f1;
    line-height: 40px;
  }
  &-main{
    display: flex;
    flex-wrap: wrap;
    .item{
      width: 50%;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 0 10px;
      box-sizing: border-box;
      img{
        width: 100%;
      }
      .title{
        width: 100%;
        line-height: 30px;
        color:#333;
        font-size: 14px;
        font-weight: 900;
        overflow:hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      &-action{
        width: 100%;
        height: 30px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        color:#f66;
      }
    }
  }
}
</style>
